<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome</title>
</head>
<body>
<h1>网站首页</h1>
<h4>Logged in.</h4>
<h4>Welcome,<span class="username"></span></h4>

<script>

    function getCookieValue(key) {
        const name = key + "=";
        const cs = document.cookie.split(';');
        for (let i = 0; i < cs.length; i++) {
            const c = cs[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
    }

    // 当使用session的时候 客户端取不到cookie里面的sessionId 以为它是httponly的形式
    const cookie = document.cookie
    console.log('cookie is:', cookie)
    const status = getCookieValue('is_login')
    const val = getCookieValue('username')
    console.log('username is:', val)
    if (!status || status !== 'True') {
        window.location.href = '/app/login'
    } else {
        document.getElementsByClassName('username')[0].innerText = val
    }
</script>
</body>
</html>